package com.yangjian.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yangjian.bean.User;
import com.yangjian.dao.UserDao;
import com.yangjian.dto.Code;
import com.yangjian.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Transactional
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserDao dao;

    /**
     * 根据电话查询用户
     *
     * @param phone
     * @return
     */
    @Override
    public User findByFhone(String phone) {

        LambdaQueryWrapper<User> lqw  = new LambdaQueryWrapper<>();
        lqw.eq(User::getPhone,phone);
        lqw.eq(User::getStatus,1);
        User user = dao.selectOne(lqw);


        return user;
    }

    /**
     * 添加用户
     *
     * @param user
     * @return
     */
    @Override
    public int add(User user) {
        int row = dao.insert(user);
        return row;
    }

    /**
     * 根据用户本身的id查询用户
     *
     * @param id
     * @return
     */
    @Override
    public User findById(Long id) {
        User user = dao.selectById(id);
        return user;
    }
}
